﻿
module("FallingL.init")
test("FallingL init", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingL = new tetris.FallingL(x, y, color);
    equal(5, fallingL.center.x, "CenterX of FallingL is set");
    equal(6, fallingL.center.y, "CenterY of FallingL is set");

    var relativeBody="";
    for (var i = 0; i < fallingL._relativeBody.length; i++) {
        relativeBody += fallingL._relativeBody[i].coordinate.toString() + " ";
    }
    equal("(0,-1) (0,0) (0,1) (1,1) ", relativeBody, "CenterY of FallingL is set");

    var body= "";
    for (var i = 0; i < fallingL.getBody.length; i++) {
        body += fallingL.getBody[i].coordinate.toString() + " ";
    }
    equal("(5,5) (5,6) (5,7) (6,7) ", body, "CenterY of FallingL is set");
});

test("FallingL moveTo", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingL = new tetris.FallingL(x, y, color);
    fallingL.moveTo(7, 8);

    deepEqual(7, fallingL.center.x, "CenterX of FallingL is set to new x");
    equal(8, fallingL.center.y, "CenterY of FallingL is set to new y");

    var relativeBody = "";
    for (var i = 0; i < fallingL._relativeBody.length; i++) {
        relativeBody += fallingL._relativeBody[i].coordinate.toString() + " ";
    }
    equal("(0,-1) (0,0) (0,1) (1,1) ", relativeBody, "CenterY of FallingL is set");

    var body = "";
    for (var i = 0; i < fallingL.getBody.length; i++) {
        body += fallingL.getBody[i].coordinate.toString() + " ";
    }
    equal("(7,7) (7,8) (7,9) (8,9) ", body, "CenterY of FallingL is set");
});

test("FallingL moveRight", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingL = new tetris.FallingL(x, y, color);
    fallingL.moveRight(); 
    deepEqual(6, fallingL.center.x, "CenterX of FallingL is set to x+1");
    equal(8, fallingL.center.y, "CenterY of FallingL is same");
});

test("FallingL moveLeft", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingL = new tetris.FallingL(x, y, color);
    fallingL.moveLeft();
    deepEqual(4, fallingL.center.x, "CenterX of FallingL is set to x-1");
    equal(8, fallingL.center.y, "CenterY of FallingL is same");
});

test("FallingL moveUp", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingL = new tetris.FallingL(x, y, color);
    fallingL.moveUp();
    equal(5, fallingL.center.x, "CenterX of FallingL is same");
    equal(7, fallingL.center.y, "CenterY of FallingL is set to y-1");
});

test("FallingL moveDown", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingL = new tetris.FallingL(x, y, color);
    fallingL.moveDown();
    equal(5, fallingL.center.x, "CenterX of FallingL is same");
    equal(9, fallingL.center.y, "CenterY of FallingL is set to y+1");
});

test("FallingL rotate", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingL = new tetris.FallingL(x, y, color);
    fallingL.rotate();
    equal(90, fallingL.rotation, "Rotation of FallingL is set to 90");
});

test("FallingL rotate twice", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingL = new tetris.FallingL(x, y, color);
    fallingL.rotate();
    equal(90, fallingL.rotation, "Rotation of FallingL is set to 90");
    fallingL.rotate();
    equal(180, fallingL.rotation, "Rotation of FallingL is set to 180");
});

test("FallingL rotateBack", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingL = new tetris.FallingL(x, y, color);
    fallingL.rotateBack();
    equal(270, fallingL.rotation, "Rotation of FallingL is set to 270");   
});

test("FallingL rotateTo", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingL = new tetris.FallingL(x, y, color);
    fallingL.rotateTo(180);
    equal(180, fallingL.rotation, "Rotation of FallingL is set to 180");
});

